﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;

namespace ScannerDemo
{
    class Vcard
    {
        public string name { get; set; }
        public string tel { get; set; }
        public string email { get; set; }
        public string company { get; set; }
        public string occupation { get; set; }
        public Vcard()
        {
            
        }
        public async Task WriteFile(string fileName, string text) { IStorageFolder applicationFolder = ApplicationData.Current.LocalFolder; IStorageFile storageFile = await applicationFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); using (Stream stream = await storageFile.OpenStreamForWriteAsync()) { byte[] content = Encoding.UTF8.GetBytes(text); await stream.WriteAsync(content, 0, content.Length); } }
        
        public string generateString()
        {
            string resultStr =
                @"BEGIN:VCARD
VERSION:2.1";

            if ((name != null) && (name != ""))
            {
                resultStr += @"
FN:"+name;
            }
            if ((tel != null) && (tel != ""))
            {
                resultStr += @"
TEL;CELL:" + tel;
            }
            if ((email != null) && (email != ""))
            {
                resultStr += @"
EMAIL:" + email;
            }
            if ((company != null) && (company != ""))
            {
                resultStr += @"
ORG:" + company;
            }
            if ((occupation != null) && (occupation != ""))
            {
                resultStr += @"
TITLE:" + occupation;
            }
            resultStr += @"
END:VCARD";


            return resultStr;

        }


    }
}
